package priv.conceit.sc.hoxton.file.handle.preview;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import priv.conceit.sc.hoxton.common.util.FileSuffixUtil;
import priv.conceit.sc.hoxton.file.config.FileProperties;

/**
 * sc-hoxton
 *
 * @author Conceit
 * 2020/5/27 增加方法
 * @since 1.0.0, 2020/5/27
 */
@Component
public class PreviewHandleFactory {

	@Autowired
	CadPreviewHandle cadPreviewHandle;
	@Autowired
	CompressPreviewHandle compressPreviewHandle;
	@Autowired
	MusicPreviewHandle musicPreviewHandle;
	@Autowired
	OfficePreviewHandle officePreviewHandle;
	@Autowired
	PdfPreviewHandle pdfPreviewHandle;
	@Autowired
	PicturePreviewHandle picturePreviewHandle;
	@Autowired
	TextPreviewHandle textPreviewHandle;
	@Autowired
	VideoPreviewHandle videoPreviewHandle;
	@Autowired
	DefaultPreviewHandle defaultPreviewHandle;

	@Autowired
	FileProperties fileProperties;

	/** 
	 * create
	 * 
	 * @param savedFileName
	 * @return priv.conceit.sc.hoxton.file.source.handle.preview.AbsPreviewHandle
	 * @author conceit
	 * @date 2020/5/27 11:53
	 */
	public AbsPreviewHandle create(String savedFileName){
		if(StrUtil.isBlank(savedFileName)){
			throw new IllegalArgumentException();
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getMusicSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return musicPreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getPdfSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return pdfPreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getPictureSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return picturePreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getTextSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return textPreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getVideoSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return videoPreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getOfficeSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return officePreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getCadSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return cadPreviewHandle;
		}
		if(FileSuffixUtil.fileNameAnyMatch(fileProperties.getPreview().getCompressSuffixs(),savedFileName,fileProperties.getPreview().getIgnoreCase())){
			return compressPreviewHandle;
		}
		return defaultPreviewHandle;
	}
}
